package com.xzy.security;

import com.xzy.entities.SysUser;
import com.xzy.service.SysUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

/**
 * TODO70
 *
 * @author Administrator
 * ClassName: UserUtils
 * date: 2021/11/12 11:40
 */

@Component
public class UserUtils {

    @Autowired
    private SysUserService userService;

    public SysUser getUser() {
        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = userDetails.getUsername();
        SysUser user = userService.findByUserName(username);
        return user;
    }
}
